#ifndef TCPSERVER_H
#define TCPSERVER_H
#include"INet.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <list>
#include <map>

// //sock--包大小，缓冲区，偏移量
struct stru_pack{
    int   m_nPackSize;
    char *m_pszbuf;
    int   m_noffset;
};
class TCPServer:public INet
{
public:
    TCPServer();
    ~TCPServer();
public:
    bool initNetWork(const char* szip ="127.0.0.1",short nport = 1234);
    void unInitNetWork(const char *szerr = "");
    bool sendData(SOCKET sock,const char* szbuf,int nlen);
    void recvData();
public:
    static DWORD WINAPI ThreadAccept(LPVOID lpvoid);
    static DWORD WINAPI ThreadRecv(LPVOID lpvoid);
private:
    SOCKET m_socklisten;//客户端套接字句柄
    std::list<HANDLE> m_lstThread;
    bool  m_bFlagQuit;//子线程的开关
public:

    std::list<SOCKET> m_lstSocket;
    fd_set m_fdsets;
    std::map<SOCKET,stru_pack*> m_mapSocketToPack;
};

#endif // TCPSERVER_H
